<!DOCTYPE html>
<html>
<head>
    <meta content="text/html" charset="UTF-8">
    <title>微信管理平台</title>
    <link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
    <link rel="stylesheet" href="css/themes/icon.css"/>
    <link rel="stylesheet" href="css/themes/color.css"/>
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <link rel="stylesheet" type="text/css" href="css/themes/portal.css"/>
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-layout" fit="true">
    <div data-options="region:'center',split:true,border:false">
        <table id="weixin_menu_treegird"></table>
    </div>
</div>

<div style="display: none">
    <div id="weixin_menus_contmenu" class="easyui-menu" data-options="onClick:menuHandler" style="width:120px;">
        <div data-options="name:'new'">新建菜单</div>
        <div data-options="name:'new2',iconCls:'icon-save'">新建子菜单</div>
        <div class="menu-sep"></div>
        <div data-options="name:'exit'">退出</div>
    </div>
</div>
<script type="text/javascript">
    var $weixin_menu_treegird = $('#weixin_menu_treegird');
    var $weixin_menus_contmenu=$('#weixin_menus_contmenu');
    $weixin_menu_treegird.treegrid({
        aaaa: [],
        url: 'data/weixinmenu.json',
        idField: 'id',
        treeField: 'text',
        fit: true,
        pagination:true,
        columns: [
            [
                {field: 'ck', checkbox: true},
                {title: '菜单名称', field: 'text', width: 150, editor: {type: 'textbox', options: {required: true}}},
                {title: '菜单类型', field: 'type', width: 80, editor: {type: 'textbox', options: {required: true}}},
                {field: 'enable', title: '激活', editor: {type: 'checkbox', options: {on: 'true', off: 'false'}}},
                {field: 'key', title: 'key', width: 80,editor: {type: 'textbox', options: {required: true}}},
                {field: 'url', title: '链接(type为view情况下使用)', width: 200,editor: {type: 'textbox', options: {required: true}}},
                {field: 'uaarl', title: '消息处理器', width: 400,editor: {type: 'combogrid',
                    options: {
                        required: true,
                        idField:'id',
                        textField:'retype',
                        url:'data/msgrole.json',
                        columns:[[
                            {field: 'retype', title: '返回类型',width:100},
                            {field: 'msgid', title: '消息id'},
                            {field: 'stime', title: '开始时间', width: 180},
                            {field: 'endtime', title: '结束时间', width: 180},
                            {field: 'plugin', title: '对应插件', width: 180}
                        ]]
                    }
                }}
            ]
        ],
        onContextMenu:function(e, row){
            e.preventDefault();
            console.log(row);
            $weixin_menus_contmenu.menu('show', {
                left: e.pageX,
                top: e.pageY
            });
            $weixin_menus_contmenu.menu('options').row=row;

    },
        onBeforeEdit: function (row) {
            var a = $weixin_menu_treegird.treegrid('options');
            a.aaaa.push(row);
        },
        onDblClickRow:function(row){
            $weixin_menu_treegird.treegrid('beginEdit', row.id);
        },
        toolbar: [
            {
                iconCls: 'icon-edit',
                text: '开始编辑',
                handler: function () {
                    alert('编辑按钮')
                }
            },
            '-',
            {
                iconCls: 'icon-save',
                text: '保存',
                handler: function () {
                    var a = $weixin_menu_treegird.treegrid('options');
                    $.each(a.aaaa, function (i, n) {

                        $weixin_menu_treegird.treegrid('endEdit', n.id);
                    })
                }
            },
            {
                iconCls: 'icon-save',
                text: '同步到服务器',
                handler: function () {
                    var change=$weixin_menu_treegird.treegrid('getChanges');
                    console.log(change);
                }
            }
        ]

    });
    var menuindex=-1;
    function menuHandler(menu){
        console.log(menu);
        var row=$weixin_menus_contmenu.menu('options').row;
        switch (menu.name)
        {
            case 'new':
                alert('new');
                $weixin_menu_treegird.treegrid('append', {
                    parent:row._parentId,
                    data: [{
                        "id": menuindex--,
                        "text": "新菜单",
                        "iconCls": "icon-save",
                        "type":"event",
                        "enable":true
                    }]
                });
                $weixin_menu_treegird.treegrid('beginEdit',menuindex+1);
                break;
            case 'new2':
                alert('new2');
                break;
            default:
        }
    }
</script>
</body>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.portal.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/jquery.edatagrid.js"></script>
</html>